package tiltmaze.view;

import java.awt.Frame;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

/**
 * About Box
 * @author Juraj Nižnan
 */
public class AboutBox extends JDialog {

    private JButton closeButton;

    public AboutBox(Frame owner) {
        super(owner);
        initComponents();
        getRootPane().setDefaultButton(closeButton);
    }

    private void initComponents() {
        setTitle("About");
        closeButton = new JButton();
        JLabel appTitleLabel = new JLabel();
        JLabel versionLabel = new JLabel();
        JLabel appVersionLabel = new JLabel();
        JLabel authorLabel = new JLabel();
        JLabel appAuthorLabel = new JLabel();
        JLabel homepageLabel = new JLabel();
        JTextField appHomepageLabel = new JFormattedTextField();
        JLabel appDescLabel = new JLabel();

        setModal(true);
        setResizable(false);

        closeButton.setText("Close");
        closeButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                Window w = SwingUtilities.getWindowAncestor(closeButton);
                if (w != null) {
                    w.setVisible(false);
                }
            }
        });

        appTitleLabel.setFont(appTitleLabel.getFont().deriveFont(appTitleLabel.getFont().getStyle() | java.awt.Font.BOLD, appTitleLabel.getFont().getSize() + 4));
        appTitleLabel.setText("Tilt Maze Generator");

        versionLabel.setFont(versionLabel.getFont().deriveFont(versionLabel.getFont().getStyle() | java.awt.Font.BOLD));
        versionLabel.setText("Product Version:");

        appVersionLabel.setText("1.0");

        authorLabel.setFont(authorLabel.getFont().deriveFont(authorLabel.getFont().getStyle() | java.awt.Font.BOLD));
        authorLabel.setText("Author:");

        appAuthorLabel.setText("Juraj Nižnan");

        homepageLabel.setFont(homepageLabel.getFont().deriveFont(homepageLabel.getFont().getStyle() | java.awt.Font.BOLD));
        homepageLabel.setText("Homepage:");

        appHomepageLabel.setText("http://code.google.com/p/tilt-maze-generator/");
        appHomepageLabel.setBorder(null);
        appHomepageLabel.setOpaque(false);
        appHomepageLabel.setEditable(false);

        appDescLabel.setText("<html>A simple Java application for generating and solving tilt mazes.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(versionLabel).addComponent(authorLabel).addComponent(homepageLabel)).addGap(67, 67, 67).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(appAuthorLabel).addComponent(appVersionLabel).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(closeButton).addComponent(appHomepageLabel)))).addComponent(appTitleLabel).addComponent(appDescLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)).addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(appTitleLabel).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(appDescLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(versionLabel).addComponent(appVersionLabel)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(authorLabel).addComponent(appAuthorLabel)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(homepageLabel).addComponent(appHomepageLabel)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(closeButton).addContainerGap(25, Short.MAX_VALUE)));

        pack();
    }
}
